Port scanner code

import socket def simple_port_scanner(target, ports): print(f"Scanning {target}...") for port in ports: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(1) # 1 second timeout result = sock.connect_ex((target, port)) if result == 0: print(f"Port {port} is OPEN") else: print(f"Port {port} is closed") sock.close() # Example usage target_ip = "127.0.0.1" # Replace with target IP ports_to_scan = [22, 80, 443, 8080] # Add more ports as needed simple_port_scanner(target_ip, ports_to_scan)

Code output

Scanning 127.0.0.1... Port 22 is closed Port 80 is closed Port 443 is closed Port 8080 is closed